﻿<lib:AppPage
    x:Class="CloudEmoticon.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:my="clr-namespace:CloudEmoticon"
    xmlns:lib="clr-namespace:Simon.Library.Controls"
    xmlns:cmd="clr-namespace:NaveenDhaka"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:longListSelector="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.LongListSelector"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    shell:SystemTray.BackgroundColor="#FF4CBEE8" 
    AppTitle="{Binding LocalizedResources.ApplicationTitle, Source={StaticResource LocalizedStrings}}"
    Loaded="AppPage_Loaded">

    <toolkit:TransitionService.NavigationInTransition>
        <toolkit:NavigationInTransition>
            <toolkit:NavigationInTransition.Backward>
                <toolkit:SlideTransition Mode="SlideDownFadeIn"/>
            </toolkit:NavigationInTransition.Backward>
        </toolkit:NavigationInTransition>
    </toolkit:TransitionService.NavigationInTransition>
    <toolkit:TransitionService.NavigationOutTransition>
        <toolkit:NavigationOutTransition>
            <toolkit:NavigationOutTransition.Forward>
                <toolkit:SlideTransition Mode="SlideUpFadeOut"/>
            </toolkit:NavigationOutTransition.Forward>
        </toolkit:NavigationOutTransition>
    </toolkit:TransitionService.NavigationOutTransition>

    <lib:AppPage.Resources>
        <DataTemplate x:Key="GroupHeaderTemplate">
            <Border Background="{StaticResource PhoneAccentBrush}" BorderThickness="0" Margin="15,15,0,0" HorizontalAlignment="Left">
                <TextBlock Text="{Binding Name}" Foreground="White" 
                           FontSize="24" Margin="20,15,25,15" FontFamily="{StaticResource PhoneFontFamilySemiLight}"
                           HorizontalAlignment="Left" VerticalAlignment="Center"/>
            </Border>
        </DataTemplate>

        <Style x:Key="JumpListStyle" TargetType="longListSelector:LongListSelectorEx">
            <Setter Property="ItemTemplate" Value="{StaticResource GroupHeaderTemplate}" />
        </Style>

        <DataTemplate x:Key="ItemTemplate">
            <Border 
                BorderBrush="{StaticResource PhoneBorderBrush}" BorderThickness="0,0,0,3"
                cmd:CommandExecuter.OnEvent="Tap" cmd:CommandExecuter.Command="{StaticResource CopyCommand}"
                cmd:CommandExecuter.CommandParameter="{Binding Text}">
                <toolkit:ContextMenuService.ContextMenu>
                    <toolkit:ContextMenu
                        cmd:CommandExecuter.OnEvent="Opened"
                        cmd:CommandExecuter.Command="{StaticResource RefreshDataCommand}"
                        cmd:CommandExecuter.CommandParameter="{Binding RelativeSource={RelativeSource Self}}">
                        <toolkit:MenuItem
                            Header="{Binding LocalizedResources.Copy, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
                            FontFamily="{StaticResource PhoneFontFamilyNormal}" FontWeight="Bold"
                            Command="{StaticResource CopyCommand}" CommandParameter="{Binding Text}" />
                        <toolkit:MenuItem 
                            Header="{Binding LocalizedResources.Edit, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
                            Command="{StaticResource EditCommand}" CommandParameter="{Binding}"
                            Visibility="{Binding IsEnabled, Converter={StaticResource EnableToVisibilityConverter}, RelativeSource={RelativeSource Self}}"/>
                        <toolkit:MenuItem 
                            Header="{Binding LocalizedResources.Pin, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
                            Command="{StaticResource PinCommand}" CommandParameter="{Binding}"
                            Visibility="{Binding IsEnabled, Converter={StaticResource EnableToVisibilityConverter}, RelativeSource={RelativeSource Self}}"/>
                        <toolkit:MenuItem
                            Header="{Binding LocalizedResources.AddFavorite, Mode=OneWay, Source={StaticResource LocalizedStrings}}" 
                            Command="{StaticResource AddFavoriteCommand}" CommandParameter="{Binding}"
                            Visibility="{Binding IsEnabled, Converter={StaticResource EnableToVisibilityConverter}, RelativeSource={RelativeSource Self}}"/>
                        <toolkit:MenuItem 
                            Header="{Binding LocalizedResources.RemoveFavorite, Mode=OneWay, Source={StaticResource LocalizedStrings}}" 
                            Command="{StaticResource RemoveFavoriteCommand}" CommandParameter="{Binding Text}"
                            Visibility="{Binding IsEnabled, Converter={StaticResource EnableToVisibilityConverter}, RelativeSource={RelativeSource Self}}"/>
                    </toolkit:ContextMenu>
                </toolkit:ContextMenuService.ContextMenu>
                <Grid Background="Transparent">
                    <TextBlock Text="{Binding Text}" FontSize="26" Margin="15,15,0,25" FontFamily="/CloudEmoticon;component/Fonts/seguisym.ttf#Segoe UI Symbol" MinHeight="33"/>
                    <TextBlock Text="{Binding Note}" Margin="15,0,0,0" 
                               FontFamily="{StaticResource PhoneFontFamilySemiLight}" FontSize="22" 
                               Foreground="{StaticResource PhoneDisabledBrush}" 
                               VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
                </Grid>
            </Border>
        </DataTemplate>
    </lib:AppPage.Resources>

    <phone:Pivot
        x:Name="pivot"
        SelectionChanged="pivot_SelectionChanged"
        HeaderTemplate="{StaticResource HeaderTemplate}">
        <phone:PivotItem x:Name="recentPage" Margin="12, 0" Header="{Binding LocalizedResources.Recent, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
            <longListSelector:LongListSelectorEx
                x:Name="RecentSelector"
                ItemTemplate="{StaticResource ItemTemplate}"
                ItemsSource="{Binding RecentList}"/>
        </phone:PivotItem>
        <phone:PivotItem Margin="12, 0" Header="{Binding LocalizedResources.Favorite, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
            <Grid>
                <TextBlock
                    x:Name="ListEmptyLabel" 
                    VerticalAlignment="Center" TextWrapping="Wrap" FontSize="24" Margin="35,0" 
                    Text="{Binding LocalizedResources.ListEmpty, Mode=OneWay, Source={StaticResource LocalizedStrings}}" />
                <longListSelector:LongListSelectorEx
                    x:Name="FavoriteSelector"
                    ItemTemplate="{StaticResource ItemTemplate}"
                    ItemsSource="{Binding FavoriteList}"/>
            </Grid>
        </phone:PivotItem>
        <phone:PivotItem Margin="12, 0" Header="{Binding LocalizedResources.Repositories, Mode=OneWay, Source={StaticResource LocalizedStrings}}">
            <longListSelector:LongListSelectorEx
                x:Name="EmoticonSelector" IsGroupingEnabled="True"
                GroupHeaderTemplate="{StaticResource GroupHeaderTemplate}" 
                ItemsSource="{Binding EmoticonList}"
                ItemTemplate="{StaticResource ItemTemplate}"
                JumpListStyle="{StaticResource JumpListStyle}"/>
        </phone:PivotItem>
    </phone:Pivot>

    <lib:AppPage.AppBar>
        <lib:AppBar Mode="Minimized">
            <lib:AppBarIconButton 
                Text="{Binding LocalizedResources.Add, Mode=OneWay, Source={StaticResource LocalizedStrings}}" 
                IconUri="/Images/add.png"
                Click="AppBarAddButton_Click"/>
            <lib:AppBarIconButton
                Text="{Binding LocalizedResources.Refresh, Mode=OneWay, Source={StaticResource LocalizedStrings}}" 
                IconUri="/Images/refresh.png"
                Click="AppBarRefreshButton_Click" />
            <lib:AppBarMenuItem 
                Text="{Binding LocalizedResources.SettingAndAbout, Mode=OneWay, Source={StaticResource LocalizedStrings}}"
                Click="AppBarSettingButton_Click"/>
        </lib:AppBar>
    </lib:AppPage.AppBar>
</lib:AppPage>